package com.syni.mdd.sjb.common.component.utils.common.utils;

import com.github.houbb.opencc4j.util.ZhConverterUtil;

import java.util.HashMap;

/**
 * @className ParamsMap
 * @description TOO
 * @Author cfx
 * @DATE 2019/9/5 15:00
 * @VERSION 1.0
 **/
public class ParamsMap extends HashMap {
    public String getString(String key){
        if(this.containsKey(key) && StringUtils.checkNullAndEmpty(this.get(key))){
            return this.get(key).toString();
        }
        return null;
    }

    public String getString(String key,String DEFAULT_STR){
        if(this.containsKey(key) && StringUtils.checkNullAndEmpty(this.get(key))){
            return this.get(key).toString();
        }
        return DEFAULT_STR;
    }

    /**
     * @Description 获取值（繁体转简体）
     * @Author: cfx
     * @Date: 2019/11/10
     */
    public String getStringSimple(String key){
        if(this.containsKey(key) && StringUtils.checkNullAndEmpty(this.get(key))){
            //去重emojo表情符
            String paramStr = WebUtils.replaceEmoji(this.get(key).toString());
            return ZhConverterUtil.convertToSimple(paramStr);
        }
        return null;
    }

    public Integer getInteger(String key){
        if(this.containsKey(key) && StringUtils.checkNullAndEmpty(this.get(key))){
            return Integer.parseInt(this.get(key).toString());
        }
        return null;
    }

    public Double getDouble(String key){
        if(this.containsKey(key) && StringUtils.checkNullAndEmpty(this.get(key))){
            String value = this.getString(key);
            if(StringUtils.isNotBlank(value)) {
                return Double.parseDouble(value);
            }
        }
        return null;
    }
}
